<?php

/**
 * ClassName:用户操作类
 * @auditor LeiJunXiang
 * @time 2024/11/08
 */

namespace app\modelOpreate\user;

use app\modelOpreate\invite\Invite;
use app\modelOpreate\ModelOpeBase;
use think\facade\Db;

class ForumUserOpe extends ModelOpeBase
{
    const TOOL_FORUM_USER_OPE = "ForumUserOpe";
    protected $pk = 'userId';

    /**
     * 新增用户
     * @return void
     */
    public function insertUser($arr)
    {
        $db = Db::table($this->table);
        $flag = $db->insert($arr);
        return $flag;
    }


    /**
     * 获取关注用户id列表(用户id)
     * @return void
     */
    public function getAttentionUserIdList($userId)
    {
        $list = [];
        if ($userId) {
            $list = Db::table($this->table)
                ->where('userId', $userId)
                ->field('attentionUserIdList')
                ->find();
        }
        return $list;
    }


    /**
     * 增加关注用户id(用户id,关注用户id)
     */
    public function addAttentionUserId($userId, $attentionUserId)
    {
        $flag = Db::table($this->table)
            ->where('userId', $userId)
            ->update([
                'attentionUserIdList' => Db::raw("JSON_ARRAY_APPEND(attentionUserIdList, '$', '" . $attentionUserId . "')")
            ]);
        return $flag;
    }

    /**
     * 增加粉丝用户id(用户id,粉丝用户id)
     */
    public function addFanUserId($userId, $fanUserId)
    {
        $flag = Db::table($this->table)
            ->where('userId', $fanUserId)
            ->update([
                'fanUserIdList' => Db::raw("JSON_ARRAY_APPEND(fanUserIdList, '$', '" . $userId . "')")
            ]);
        return $flag;
    }

    /**
     * 新增粉丝数
     * @return void
     */
    public function addFanNumber($userId)
    {
        $flag = Db::table($this->table)
            ->where('userId', $userId)
            ->inc('fan')
            ->update();
        return $flag;
    }

    /**
     * 新增关注数
     */
    public function addAttentionNumber($userId)
    {
        $flag = Db::table($this->table)
            ->where('userId', $userId)
            ->inc('attention')
            ->update();
        return $flag;
    }

}